package com.lz.football.module.chat
{
	import com.global.GlobalDef;
	import com.greensock.TweenLite;
	import com.greensock.easing.Linear;
	
	import flash.display.GradientType;
	import flash.display.Shape;
	import flash.events.Event;
	import flash.filters.BitmapFilterQuality;
	import flash.filters.GlowFilter;
	import flash.geom.Matrix;
	import flash.text.TextField;
	import flash.text.TextFormat;
	
	import lz.controls.core.TitleWindow;
	
	public class NoticeView extends TitleWindow implements INoticeView
	{
		private var _noticeText:TextField;
		/**
		 * 等待的公告 
		 */
		private var _noticeDate:Array;
		/**
		 *[lv,showTime,type,playerName,goodsName] 
		 */
		private var _tempArr:Array;
		/**
		 * 
		 */
		private var _changeTime:int;
		private var _tweenlite:TweenLite;
		
		
		/**
		 * 
		 */
		private var _noticInfo:String;
		public function NoticeView()
		{
			super();
		}
		
		public function initUI(view:Object=null):void
		{
			
			var mat:Matrix = new Matrix();
			mat.createGradientBox(500,25,0);
			
			
			
			var shape:Shape = new Shape();
			shape.graphics.clear();
			shape.graphics.beginGradientFill(GradientType.LINEAR,[0x000000,0x000000,0x000000,0x000000],[0,0.6,0.6,0],[0,63,190,255],mat);
			//			shape.graphics.beginFill(0x000000,0.6);
			shape.graphics.drawRect(0,0,500,20);
			shape.graphics.endFill();
			this.addChild(shape);
			_noticeText = new TextField();
			var tf:TextFormat = new TextFormat();
			tf.color = 0xFFFFFF;
			tf.size = 12;
			//			tf.bold = true;
			
			var filter:GlowFilter = new GlowFilter(0x000000);
			filter.blurX = 2;
			filter.blurY = 2;
			filter.strength = 1;
			filter.quality = BitmapFilterQuality.MEDIUM;
			filter.knockout = false;
			_noticeText.filters = [filter];
			_noticeText.defaultTextFormat = tf;
			_noticeText.width = 500;
			_noticeText.height = 20;
			this.addChild(_noticeText);
			_noticeText.mouseEnabled = false;
			shape = new Shape();
			shape.graphics.clear();
			shape.graphics.beginFill(0xFF0000,0.1);
			shape.graphics.drawRect(0,0,500,30);
			shape.graphics.endFill();
			this.addChild(shape);
			_noticeText.mask = shape;
			GlobalDef.GameStage.addEventListener(Event.RESIZE,onResizeHandler);
			onResizeHandler(null);
			this.mouseChildren = false;
			this.mouseEnabled = false;
		}
		override protected function onResizeHandler(e:Event):void
		{
			this.x = (GlobalDef.StageWidth - 500)>> 1;
			this.y = 80
		}
		/**
		 * 获得公告 
		 * @param $obj
		 * 
		 */
		public function getNotice($obj:Object):void
		{
			if(_noticeDate == null)_noticeDate = [];
			var arr:Array = $obj.array;
			_noticeDate = _noticeDate.concat(arr);
//			_noticeDate.sort(sorton);
//			function sorton($a:Array,$b:Array):Number
//			{
//				if($a[0] > $b[0])return -1;
//				if($a[0] < $b[0])return 1;
//				return 0;
//			}
			if(this.parent == null)
			{
				checkOut();
			}
			
		}
		
		/**
		 * 检查是否还有需要显示的公告 
		 * 
		 */
		private function checkOut():void
		{
			if(_noticeDate.length > 0)
			{
				_noticInfo = _noticeDate.shift();//[lv,showTime,type,playerName,goodsName]
				GlobalDef.GameStage.addChild(this);
				_changeTime = 0;
				setText();
				_noticeText.width = _noticeText.textWidth + 5;
				_noticeText.x = 500;
				TweenLite.to(_noticeText,2,{x:((500-_noticeText.width) >> 1),onComplete:oncompleteInt,ease:Linear.easeInOut,onUpdate:changeColor/*,onUpdateParams:[_tempArr[2]]*/})//,onUpdate:onUpdate/*,onUpdateParams:[_tempArr[2]]*/})
			}
		}
		/**
		 * 完成进入状态
		 * 
		 */
		private function oncompleteInt():void
		{
			TweenLite.to(_noticeText,5,{onUpdate:changeColor/*,onUpdateParams:[_tempArr[2]]*/,onComplete:delayComplete});//暂停
		}
		/**
		 * 暂停完成 
		 * 
		 */
		private function delayComplete():void
		{
			TweenLite.to(_noticeText,2,{x:-_noticeText.width,onComplete:onCompleteOut,ease:Linear.easeInOut,onUpdate:changeColor/*,onUpdateParams:[_tempArr[2]]*/});
		}
		/**
		 * 完成退出状态 
		 * 
		 */
		private function onCompleteOut():void
		{
			_noticeText.x = 500;
			if(this.parent)
				this.parent.removeChild(this);
			checkOut();
		}
		
		private function changeColor($value:int = 0):void
		{
			var color:String;
			color = "#000000";
			if(_changeTime < 5)
			{
				color = "#CCCCCC";
			}else if(_changeTime < 10)
			{
				color = "#53D74F";
			}else if(_changeTime < 15)
			{
				color = "#00CCFF";
			}else if(_changeTime < 20)
			{
				color = "#C16DFA";
			}else if(_changeTime < 25)
			{
				color = "#FF9900";
			}else if(_changeTime < 30)
			{
				color = "#FF3300";
			}else 
			{
				color = "#000000";
			}
			_changeTime++;
			if(_changeTime > 40)
			{
				_changeTime = 0;
			}
			setText(color);
		}
		/**
		 * 设置文本颜色值
		 * 
		 */
		private function setText(color:String = "#000000"):void
		{
			_noticeText.htmlText = _noticInfo;
//			return;
//			var str:String = "";
//			switch(_tempArr[2])
//			{
//				case 1:
//					str = _tempArr[3];
//					break;
//				case 2://获得了红卡
//					str = "<font color = '#FF9900'>"+_tempArr[3] + "</font>通过球员探索功能获取了" + "<b><font color = '#FF3300' size = '14'>"+_tempArr[4]+"</font></b>";
//					break;
//				case 3://获得黑
//					str = "<font color = '#FF6600'>"+_tempArr[3] + 
//					"</font>通过球员探索功能获取了" + "<font color = '"+color+"' size = '14'>"+_tempArr[4]+"</font>";
//					break;
//				case 4://登上S级别！
//					
//					str = "<font color = '#FF9900'>"+_tempArr[3] + 
//					"</font>通过不懈努力，登上"+"<b><font color = '"+color+"' size = '16' >S</font></b>"+"级别！" ;
//					break;
//				case 5://XXX已经通过了S级巡回赛！称霸世界的梦想跨进了一大步
//					str = "<font color = '#FF9900'>"+_tempArr[3] + 
//					"</font>已经通过了<b><font color = '"+color+"' size = '16'>S</font></b>级巡回赛！称霸世界的梦想跨进了一大步" ;
//					break;
//				case 6://冲级达人XXX已经冲到50级！成为了第一阶梯的球队！
//					str = "冲级达人"+"<font color = '#FF9900'>"+_tempArr[3] + "</font>已经冲到50级！成为了第一阶梯的球队！" ;
//					break;
//				case 7://合成属性卡XXX的运气爆发了！！合成了一张XXXXX
//					str = "<font color = '#FF6600'>"+_tempArr[3] + 
//					"</font>运气爆发了！！合成了一张" +"<font color = '"+color+"' size = '14'>"+_tempArr[4]+"</font>";
//					break;
//				case 8://地球人已经没法阻止XXXX了！他已经成为了黑色球员！！
//					str = "地球人已经没法阻止"+ "<font color = '#FF9900'>"+_tempArr[3] +
//					"</font>了！他已经成为了<b><font color = '"+color+"' size = '14'>黑色球员</font></b>！！" ;
//					break;
//				case 9://XXXX获得了一张黑色洗炼卡！黑色球员就要诞生了吗！？？？？
//					str =  "<font color = '#FF9900'>"+_tempArr[3] + "</font>获得了一张黑色洗炼卡！黑色球员就要诞生了吗！？？？？" ;
//					break;
//				case 10://洗练出红色球员
//					str =  "新一代天皇巨星的诞生！"+"<font color = '#FF9900'>"+_tempArr[3] + "</font>已经是红色球员了！" ;
//					
//					break;
//				case 11://获得红色洗炼卡
//					str =  "<font color = '#FF9900'>"+_tempArr[3] + "</font>获得了一张红色洗炼卡！红色球员近在咫尺！" ;
//					break;
//				case 12://玩家通过球员探索功能获取橙色球员
//					str =  "<font color = '#FF9900'>"+_tempArr[3] + "</font>通过球员探索功能获取了" + "<b><font color = '#FF9900   '>"+_tempArr[4]+"</font></b>";
//					break;
//				case 13://玩家通过球员荣誉抽奖获取橙色球员包
//					str = "<font color = '#FF9900'>"+_tempArr[3] + "</font>在天梯赛默默耕耘，荣誉抽取了一个橙色球员包！";
//					break;
//				case 14://金棕抽红卡
//					str = "恭喜玩家<font color = '"+color+"' size = '16'>"+_tempArr[3] + 
//					"</font>在开金棕子活动中，获得了<b><font color ='#FF0000' size = '16'>红色球员包</font></b>" ;
//					break;
//				case 15://金棕抽橙卡
//					str = "恭喜玩家<font color = '"+color+"' size = '16'>"+_tempArr[3] + 
//					"</font>在开金棕子活动中，获得了<b><font color ='#FF9900' size = '16'>橙色球员包</font></b>" ;
//					break;
//				case 100://通用
//					str = "<font color = '#FFFF00' size = '14'>"+_tempArr[3] + 
//					"</font>"
//					break;
//				default:
//					str = "";
//			}
//			_noticeText.htmlText = str;
		}
		public function addEvtListener():void
		{
		}
		
		public function removeEvtListener():void
		{
		}
		
		public function destroyView():void
		{
		}
		
		public function showType($obj:Object):void
		{
		}
	}
}